/*
 * LDIR
 *
 * LDIR, a GPS cartography application built for Let's Do It Romania eco
 * campaign.
 * Copyright (C) 2010 Genera Software <office@generasoftware.com>
 *
 * http://generasoftware.com/
 *
 * This program is free software; you can redistribute it and/or modify it under
 * the terms of the GNU General Public License as published by the Free Software
 * Foundation; either version 2 of the License, or (at your option) any later
 * version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
 * details.
 *
 * You should have received a copy of the GNU General Public License along with
 * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
 * Place, Suite 330, Boston, MA 02111-1307 USA
 */
#ifndef LDIRINTERFACES_H
#define LDIRINTERFACES_H

// INCLUDES
// System Includes
#include <e32base.h>  // CBase, link against euser.lib
#include <s32strm.h>
#include <w32std.h>
#include <badesca.h>

// SERIALIZATION

class MSerializable
    {
public:
    virtual void ExternalizeL( RWriteStream& aStream ) const = 0;
    virtual void InternalizeL( RReadStream& aStream ) = 0;
    };

Internalize::Member Internalization( MSerializable* );
Externalize::Member Externalization( const MSerializable* );

class MFormFieldsValidator
    {
public:
    virtual CDesCArray* ValidateFieldsL() = 0;
    };

//
// A class for correct cleanup of RPointerArrays
template<class T>
class CleanupResetAndDestroyClose
    {
public:
    inline static void PushL( T& aRef )
        {
        CleanupStack::PushL( TCleanupItem( &Close, &aRef ) );
        }

    static void Close( TAny *aPtr )
        {
        ( STATIC_CAST(T*,aPtr) )->ResetAndDestroy();
        ( STATIC_CAST(T*,aPtr) )->Close();
        }
    };

template<class T>
inline void CleanupResetAndDestroyClosePushL( T& aRef )
    {
    CleanupResetAndDestroyClose<T>::PushL( aRef );
    }

/**
 *	\brief Data interchange format
 */
class CEntity;
class CJsonGenerator;
class CJsonParser;
class MWsObject
    {
public:
    virtual HBufC8* EncodeL( CJsonGenerator& aJsonGenerator ) = 0;
    virtual void DecodeL( const TDesC8& aJson, CJsonParser& aJsonParser ) = 0;
    virtual TInt GetIntAttribute( const TInt aAttrNameIndex, TInt& aValue ) = 0;
    virtual const TDesC& GetDesAttribute( const TInt aAttrNameIndex ) = 0;
    virtual const TDesC8& GetDes8Attribute( const TInt aAttrNameIndex ) = 0;
    virtual MWsObject* GetWsObjectL( const TInt aAttrNameIndex ) = 0;
    virtual TBool BoolAttribute( const TInt aAttrNameIndex ) = 0;
    virtual CEntity* GetEntity( const TInt aAttrNameIndex ) = 0;
    virtual void AddBoolAttributeL( const TInt aAttrNameIndex,
        const TBool aValue ) = 0;
    virtual void
    AddIntAttributeL( const TInt aAttrNameIndex, const TInt aValue ) = 0;
    virtual void AddDesAttributeL( const TInt aAttrNameIndex,
        const TDesC& aValue ) = 0;
    virtual void AddDes8AttributeL( const TInt aAttrNameIndex,
        const TDesC8& aValue ) = 0;
    // clones entity
    virtual void
    AddEntityL( const TInt aAttrNameIndex, const CEntity& aEntity ) = 0;
    };

class CWsResponse;
class MWsResponseHandler
    {
public:
    /**
     * Method to be implemented to handle a web services response.
     *
     * @param aRequestId - id of the request.
     * @param aResponseStatus - the status returned by the web service(HTTP status).
     * @param aResponse - json dom response.
     */
    virtual void HandleWsResponseL( TInt aRequestId, TInt aResponseStatus,
        CWsResponse* aResponse ) = 0;
    /**
     * Method to be implemeted to handle web services errors.
     *
     * @param aRequestId - id of the request.
     * @param aErrorCode - the error code returned by the web service.
     */
    virtual void HandleWsResponseErrorL( TInt aRequestId, TInt aErrorCode ) = 0;
    };

class MWsRequestor
    {
public:
    /**
     * Issues an asynchronous web services request.
     *
     * @param aRequestId - id of the request.
     * @param aReqObject - a request object that contains the request params
     * that will be converted to json.
     * @param aAdditionalParam - descriptor containing additional parameter if
     * meeded by the request or KNullDesC8.
     * @param aResponseHandler - observer that will handle this request.
     */
    virtual void WSRequestL( const TInt aRequestID, MWsObject* aReqObject,
        const TDesC8& aAdditionalParam, const TInt aResId,
        MWsResponseHandler* aResponseHandler ) = 0;
    /**
     * Cancels the current outstanding web services request.
     */
    virtual void CancelWsRequest() = 0;
    /**
     * Checks to see if a ws request is outstanding.
     */
    virtual TBool IsActive() = 0;
    };

#endif // LDIRINTERFACES_H
// End of File
